<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>使字符串平衡的最少删除次数</title>
</head>
<body>
  <script>
    function fn(s) {
      // 动态规划 非常非常巧妙
      let f = 0
      let b = 0
      for (let i = 0; i < s.length; i++) {
        if (s[i] == 'b')
          b++
        else {
          f = Math.min(f + 1, b)
        }
      }
      return f
    }
    console.log(fn('aababbab'))
  </script>
</body>
</html>